﻿// <copyright file="AxisSwapConverter.cs" company="Microsoft Corporation">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-03-03</date>
// <summary>Converter to subtract the converterParamter from a value</summary>

namespace NYTimes.ValueConverters
{
    using System;
    using System.Windows.Data;

    /// <summary>
    /// Axis swap converter
    /// </summary>
    public class AxisSwapConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Convert from value to parameter-value
        /// </summary>
        /// <param name="value">an integer</param>
        /// <param name="targetType">the target type</param>
        /// <param name="parameter">the conversion parameter</param>
        /// <param name="culture">the culture</param>
        /// <returns>the integer parameter - value</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int integer = (int)value;

            ////var max = int.Parse(parameter.ToString(), culture);

            ////integer = max - integer;

            return  -1 * integer;
        }

        /// <summary>
        /// Not implemented
        /// </summary>
        /// <param name="value">an integer</param>
        /// <param name="targetType">the target type</param>
        /// <param name="parameter">a value to subtract</param>
        /// <param name="culture">the conversion culture</param>
        /// <returns>parameter - value</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int integer = (int)value;

            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            var max = int.Parse(parameter.ToString(), culture);

            integer = max - integer;

            return integer;
        }

        #endregion
    }
}
